package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CategoryMapper {
    //添加分类
    @Insert("insert  into category value (null,#{type},#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    Integer save(Category category);
    //更具类别名查询
    @Select("select *from category where name=#{name}")
    Category findByName(String name);

    //查询所有类别 按照sort排序
    @Select("select * from category order by sort asc")
    List<Category> findAll();

    //根据Id删除别类
    @Delete("delete from category where id =#{id}")
    Integer deleteById(Long id);
    //修改类别
    Integer update(Category category);

    //根据类别名查询类别,排除自己
    @Select("select *from category where name=#{name} and id!=#{id}")
   Category findByName2(Category category);

    List<Category> findAllByType(Integer type);

    @Select("select * from category where id=#{id}")
    Category findById(Long id);
}
